package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.service.OrderService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: 19shusheng.com
 * @Description:
 * @Date: Created in 23:44 2020/10/30
 * @Modified By:
 */
//全局降级第二步
@RestController
@Slf4j
@RequestMapping("/order/consumer")
//@DefaultProperties(defaultFallback = "paymentInfo_errorGlobalHandler")
public class OrderController  {

    @Resource
    private OrderService orderService;

    /*    @HystrixCommand(fallbackMethod = "paymentInfo_errorHandler",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "2000")
    })*/
    @GetMapping("/payment/paymentInfoError/{id}")
    //@HystrixCommand
    public String paymentInfo_error(@PathVariable("id") Integer id) throws InterruptedException{
        return orderService.paymentInfo_error(id);
    }
    /**
     *
     * @Description: 全局降级第三步
     *
     * @auther: madonghui
     * @date: 13:19 2020/11/1
     * @param: [id]
     * @return: java.lang.String
     *
     */
    @GetMapping("/payment/paymentInfoOk/{id}")
    public String paymentInfo_ok(@PathVariable("id") Integer id){
       // int i = 10 / 0;
        return orderService.paymentInfo_ok(id);
    }

    public String paymentInfo_errorHandler(@PathVariable("id") Integer id){
        return "响应出问题了"+Thread.currentThread().getName()+"┭┮﹏┭┮";
    }
    /**
     *
     * @Description: 全局降级第一步添加全局降级方法
     *
     * @auther: madonghui
     * @date: 13:20 2020/11/1
     * @param: [id]
     * @return: java.lang.String
     *
     */
    public String paymentInfo_errorGlobalHandler(){
        return "响应出问题了"+Thread.currentThread().getName()+"┭┮﹏┭┮";
    }
}
